package basic.study.leetcode;

/**
 * @ClassName Easy160
 * @Description 相交链表
 * @Company inspur
 * @Author Kevin
 * @Date 2020/7/1 9:12
 * @Version 1.0
 */
public class Easy160 {
    public class Solution {
        public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
            if(headA == null || headB == null) {
                return null;
            }
            ListNode ha = headA;
            ListNode hb = headB;
            while (ha != hb) {
                ha = ha != null? ha.next: headB;
                hb = hb != null? hb.next: headA;
            }
            return ha;
        }
    }

    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
